package com.example.apple.studytoolbar;

import android.app.Activity;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

/**********************************************************************
 *
 *
 * @类名 Fragment1
 * @包名 com.example.apple.studytoolbar
 * @author 谢晗超
 * @创建日期 2018/7/7
 ***********************************************************************/
public class Fragment1 extends Fragment {
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.first_fragment, null);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        View mNeedShow = view.findViewById(R.id.need_show);
        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mNeedShow.getLayoutParams();

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
            layoutParams.height = 0;
        }else {
            layoutParams.height = getStatusBarHeight(getActivity());
        }
        mNeedShow.setLayoutParams(layoutParams);
    }

    public static int getStatusBarHeight(Activity activity){
        int statusBarHeight = -1;
        //获取status_bar_height资源的ID
        int resourceId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            //根据资源ID获取响应的尺寸值
            statusBarHeight = activity.getResources().getDimensionPixelSize(resourceId);
        }
        return statusBarHeight;
    }
}
